import http from '../index';
import { User } from '../model/user';

const adminPrefix = '/admin/users';

export const getUserInfo = () => http.get('/users/current');

export const getUsers = (params: string) => http.get(`${adminPrefix}?${params}`);

export const setUser = (data: User) => http.post(adminPrefix, data);

export const enableUser = (id: number) => http.put(`${adminPrefix}/${id}/enable`);

export const disableUser = (id: number) => http.put(`${adminPrefix}/${id}/disable`);

export const updateUser = async (id: number, data: { password?: string; expireDate?: string }) => {
  await http.put(`${adminPrefix}/${id}/password`, { password: data.password });
  await http.put(`${adminPrefix}/${id}/expire-date`, { expireDate: data.expireDate });
};
